package blazingbubble.gui.panels;


import java.awt.Font;

import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import blazingbubble.gui.PanelRegistry;
import blazingbubble.gui.Resources;
import blazingbubble.gui.elements.MenuLabel;
import blazingbubble.gui.elements.MenuTextField;

public class HostGameCustomOptionsPanel extends JPanel implements ChangeListener {
	private static final long serialVersionUID = 5498815399639835777L;
	
	public static final String PANEL_NAME = "HostGameCustomOptions";
	
	private static final int MIN_BUBBLES_COUNT = 1;
	private static final int MAX_BUBBLES_COUNT = 8;
	
	private static final String NORMALBUBBLESCOUNT_LABEL_TEXT = new String("Normal Bubbles Colors:");
	private static final String GHOSTBUBBLESENABLED_LABEL_TEXT = new String("Ghost Bubbles:");
	private static final String RAINBOWBUBBLES_ENABLED_LABEL_TEXT = new String("RainbowBubbles:");
	private static final String BLAZINGBUBBLES_ENABLED_LABEL_TEXT = new String("BlazingBubbles:");
	private static final String GRAVITY_ENABLED_LABEL_TEXT = new String("Gravity:");
	private static final String WIND_ENABLED_LABEL_TEXT = new String("Wind:");
	private static final String FIELDFLIPPED_ENABLED_LABEL_TEXT = new String("FlippedField:");
	private static final String TEAMS_ENABLED_LABEL_TEXT = new String("Teams:");
	
	private MenuLabel normalBubblesCountLabel = new MenuLabel(NORMALBUBBLESCOUNT_LABEL_TEXT, Font.BOLD, 12); 
	private MenuLabel ghostBubblesEnabledLabel = new MenuLabel(GHOSTBUBBLESENABLED_LABEL_TEXT, Font.BOLD, 12);
	private MenuLabel rainbowBubblesEnabledLabel = new MenuLabel(RAINBOWBUBBLES_ENABLED_LABEL_TEXT, Font.BOLD, 12); 
	private MenuLabel blazingBubblesEnabledLabel = new MenuLabel(BLAZINGBUBBLES_ENABLED_LABEL_TEXT, Font.BOLD, 12);
	private MenuLabel gravityEnabledLabel = new MenuLabel(GRAVITY_ENABLED_LABEL_TEXT, Font.BOLD, 12);
	private MenuLabel windEnabledLabel = new MenuLabel(WIND_ENABLED_LABEL_TEXT, Font.BOLD, 12);
	private MenuLabel flippedFieldEnabledLabel = new MenuLabel(FIELDFLIPPED_ENABLED_LABEL_TEXT, Font.BOLD, 12);
	private MenuLabel teamsEnabledLabel = new MenuLabel(TEAMS_ENABLED_LABEL_TEXT, Font.BOLD, 12);
		
	private JSlider normalBubblesCountSlider = new JSlider(MIN_BUBBLES_COUNT, MAX_BUBBLES_COUNT);
	private MenuTextField normalBubblesSelectedField = new MenuTextField(Resources.TEXTFIELD_SMALL_IMAGEPATH, 1, Font.PLAIN, 12);
	private JCheckBox ghostBubblesEnabledBox = new JCheckBox();
	private JCheckBox rainbowBubblesEnabledBox = new JCheckBox();
	private JCheckBox blazingBubblesEnabledBox = new JCheckBox();
	private JCheckBox gravityEnabledBox = new JCheckBox();
	private JCheckBox windEnabledBox = new JCheckBox();
	private JCheckBox flippedFieldEnabledBox = new JCheckBox();
	private JCheckBox teamsEnabledBox = new JCheckBox();
	
	public HostGameCustomOptionsPanel(){
		PanelRegistry.getInstance().registerPanel(PANEL_NAME, this);
		setUp();
	}
	
	private void setUp(){
		this.setSize(350, 270);
		this.setLayout(null);
		this.setOpaque(false);
		
		this.add(normalBubblesCountLabel);
		normalBubblesCountLabel.setBounds(5, 5, 200, 20);
		
		this.add(normalBubblesSelectedField);
		normalBubblesSelectedField.setBounds(5, 25, 20, 20);
		normalBubblesSelectedField.setText(Integer.toString(normalBubblesCountSlider.getValue()));
		normalBubblesSelectedField.setEditable(false);
		
		normalBubblesCountSlider.setMinorTickSpacing(1);
		normalBubblesCountSlider.setPaintTicks(true);
		normalBubblesCountSlider.addChangeListener(this);
		this.add(normalBubblesCountSlider);
		normalBubblesCountSlider.setBounds(25, 25, 315, 20);
		
		this.add(ghostBubblesEnabledLabel);
		ghostBubblesEnabledLabel.setBounds(5, 45, 140, 20);
		
		this.add(ghostBubblesEnabledBox);
		ghostBubblesEnabledBox.setBounds(145, 45, 20, 20);
		ghostBubblesEnabledBox.setSelected(true);
		
		this.add(blazingBubblesEnabledLabel);
		blazingBubblesEnabledLabel.setBounds(175, 45, 140, 20);
		
		this.add(blazingBubblesEnabledBox);
		blazingBubblesEnabledBox.setBounds(315, 45, 20, 20);
		blazingBubblesEnabledBox.setSelected(true);
		
		this.add(rainbowBubblesEnabledLabel);
		rainbowBubblesEnabledLabel.setBounds(5, 65, 140, 20);
		
		this.add(rainbowBubblesEnabledBox);
		rainbowBubblesEnabledBox.setBounds(145, 65, 20, 20);
		
		this.add(gravityEnabledLabel);
		gravityEnabledLabel.setBounds(175, 65, 140, 20);
		
		this.add(gravityEnabledBox);
		gravityEnabledBox.setBounds(315, 65, 20, 20);
		gravityEnabledBox.setSelected(false);
		
		this.add(windEnabledLabel);
		windEnabledLabel.setBounds(5, 85, 140, 20);
		
		this.add(windEnabledBox);
		windEnabledBox.setBounds(145, 85, 20, 20);
		windEnabledBox.setSelected(false);
		
		this.add(flippedFieldEnabledLabel);
		flippedFieldEnabledLabel.setBounds(175, 85, 140, 20);
		
		this.add(flippedFieldEnabledBox);
		flippedFieldEnabledBox.setBounds(315, 85, 20, 20);
		flippedFieldEnabledBox.setSelected(false);
		
		this.add(teamsEnabledLabel);
		teamsEnabledLabel.setBounds(5, 105, 140, 20);
		
		this.add(teamsEnabledBox);
		teamsEnabledBox.setBounds(145, 105, 20, 20);		
	}

	@Override
	public void stateChanged(ChangeEvent event) {
		if (event.getSource().equals(normalBubblesCountSlider)){
			normalBubblesSelectedField.setText(Integer.toString(normalBubblesCountSlider.getValue()));
		}
	}
	
	public int getNormalBubblesCount(){
		return normalBubblesCountSlider.getValue();
	}
	
	public boolean getGhostBubblesEnabled(){
		return ghostBubblesEnabledBox.isSelected();
	}
	
	public boolean getRainbowBubblesEnabled(){
		return rainbowBubblesEnabledBox.isSelected();
	}
	
	public boolean getBlazingBubblesEnabled(){
		return blazingBubblesEnabledBox.isSelected();
	}
	
	public boolean getGravityEnabled(){
		return gravityEnabledBox.isSelected();
	}
	
	public boolean getWindEnabled(){
		return windEnabledBox.isSelected();
	}
	
	public boolean getFlippedFieldEnabled(){
		return flippedFieldEnabledBox.isSelected();
	}
	
	public boolean getTeamsEnabled(){
		return teamsEnabledBox.isSelected();
	}
}
